package com.situ.staffmgr.dao.impl;

import java.util.List;


import com.situ.staffmgr.dao.DeptDao;
import com.situ.staffmgr.entity.Dept;
import com.situ.staffmgr.util.BaseDaoT;


public class DeptDaoImpl implements DeptDao{
	private BaseDaoT dbUtil =new BaseDaoT(); 
	@Override
	public int insert(Dept dept) {
		String sql = "insert into dept (name,room,phone,email)"+"value(?,?,?,?)";
		return dbUtil.update(sql, 
				dept.getName(),
				dept.getRoom(),
				dept.getPhone(),
				dept.getEmail());
	}

	@Override
	public int delete(int id) {
		String sql= "delete from dept where id=?";
		return dbUtil.update(sql, id);
	}

	@Override
	public int update(Dept dept) {
		String sql  ="update dept set name=?,room=?,phone=?,email=?"+"where id=?";
		return dbUtil.update(sql, 
				dept.getName(),
				dept.getRoom(),
				dept.getPhone(),
				dept.getEmail(),
				dept.getId());
	}

	@Override
	public Dept selectById(int id) {
		String sql = "select * from dept where id=?";
		return dbUtil.selectOne(Dept.class, sql, id);
	}

	@Override
	public List<Dept> selectAll() {
		// TODO Auto-generated method stub
		String sql = "select * from dept";
		return dbUtil.select(Dept.class,sql);
	}

}
